<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<strong><%@ taglib prefix="c"
                   uri="http://java.sun.com/jsp/jstl/core" %></strong>
<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    <meta charset="UTF-8">
    <title>艺术家新增</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <link rel="stylesheet" href="/xAdmin/css/font.css">
    <link rel="stylesheet" href="/xAdmin/css/xadmin.css">
    <link rel="stylesheet" href="/xAdmin/lib/layui/css/layui.css"  media="all">
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script type="text/javascript" src="/xAdmin/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="/xAdmin/js/xadmin.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>
<body>
<div class="layui-fluid">
    <div class="layui-row">
        <form method="post" class="layui-form">
            <input type="hidden" value="${user.id}" id="userid">
            <div class="layui-form-item">
                <label for="name" class="layui-form-label">
                    姓名
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="name" name="name" required="" lay-verify="required"
                           autocomplete="off" class="layui-input" value="${user.name}">
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-inline">
                    <label for="birthday" class="layui-form-label">
                        生日
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" id="birthday" name="birthday" placeholder="yyyy-MM-dd" value="${user.birthday}">
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <label for="mobilephono" class="layui-form-label">
                    手机号
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="mobilephono" name="mobilephono" required="" lay-verify="required"
                           autocomplete="off" class="layui-input" value="${user.mobilephono}">
                </div>
            </div>
            <div class="layui-form-item">
                <label for="email" class="layui-form-label">
                    邮编
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="email" name="email" required="" lay-verify="required"
                           autocomplete="off" class="layui-input" value="${user.email}">
                </div>
            </div>

            <div class="layui-form-item">
                <label  class="layui-form-label">
                    <button type="button" class="layui-btn" id="file" name="file">
                        <i class="layui-icon">&#xe67c;</i>上传图片
                    </button>
                </label>
                <div class="layui-input-block">
                    <input type="hidden" id="mainpicShowValue" value="${user.mainpic}">
                    <img src="${user.mainpicShow}" id="mainpicShow">
                </div>
            </div>

            <div class="layui-form-item">
                <label for="L_repass" class="layui-form-label">
                </label>
                <button type="button" class="layui-btn" lay-filter="add"  onclick="Issubmit()">
                    增加
                </button>
            </div>

        </form>
    </div>
</div>
<script>

    layui.use('upload', function(){
        var upload = layui.upload;
        //执行实例
        var uploadInst = upload.render({
            elem: '#file' //绑定元素
            ,url: '/ajaxData/uploadFile' //上传接口
            ,done: function(res){
                //上传完毕回调
                $("#mainpicShow").attr("src", res.srcPath);
                $("#mainpicShowValue").val(res.showPath);
            }
            ,error: function(){
                //请求异常回调
                console.log("请求异常回调");
            }
        });
    });

    $(function  () {
        layui.use('laydate', function(){
            var laydate = layui.laydate;
            laydate.render({
                elem: '#birthday'
                ,eventElem: '#birthday'
                ,trigger: 'click'
            });
        });
    });
    function Issubmit(){
        var name =  $('#name').val();
        var birthday =  $('#birthday').val();
        var mobilephono =  $('#mobilephono').val();
        var email =  $('#email').val();
        var userid= $('#userid').val();
        var mainpic =  $('#mainpicShowValue').val();
        console.log(userid);
        var date =null;
        if(userid==null||userid==""){
            data = {
                name:name,
                birthday:birthday,
                mobilephono:mobilephono,
                mainpic:mainpic,
                email:email
            };
        }else{
            data = {
                id:userid,
                name:name,
                birthday:birthday,
                mobilephono:mobilephono,
                mainpic:mainpic,
                email:email
            };
        }

        $.ajax({
            url:"/tbaUser/saveOrUpdate",
            type:'post',
            dataType:'text',
            contentType: 'application/json',
            data:JSON.stringify(data),
            timeout:2000,
            success:function(data){
                var layer = parent.layui.layer;
                if(data == 'success')
                    layer.msg('操作成功!',{icon:1,time:1000});
                else
                    layer.msg('操作失败!',{icon:1,time:1000});
                var index = parent.layer.getFrameIndex(window.name);
                parent.layer.close(index);
            },
            error:function () {
                var layer = parent.layui.layer;
                layer.msg("操作失败",{icon:1,time:1000});
            }
        })
    }

</script>

</body>

</html>
